package com.meeting.y.model;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.meeting.y.controller.YmeetingController;
import com.meeting.y.util.SqlKit;

import java.util.List;
import java.util.Map;

public class YMeetingModel extends Model<YMeetingModel> {

    public static final YMeetingModel dao = new YMeetingModel();

    public List<Record> findRooms(Map<String,Object[]> querytype, Map<String,Object> param){
        Integer userid = 1;

        String sql = "select a.id,a.name,a.description,a.create_user_manager from meetings_room a,meetings_userfollowroom b" +
                " where b.room_id = a.id and a.delete_status = 0";

        SqlKit s = new SqlKit();
        if(param!=null && !param.isEmpty()){
            if(querytype != null){
                s.buildSQL(querytype,param);
            }else {
                s.buildSQL(param);
            }
            sql+= s.getSql();
        }
        sql = sql+"order by a.id desc ";

        List<Record> list =  YmeetingController.getDB().find(sql,s.getParamArray());
        return list;
    }

    public List<Record> findAttendMeetingRooms(Map<String,Object[]> querytype, Map<String,Object> param){
        Integer userid = 1;

        String sql = "select distinct a.id,a.name,a.description,a.create_user_manager from meetings_room a,meetings_meetingattendee b,meetings_meeting c" +
                " where c.room_id = a.id and a.delete_status = 0  and b.delete_status = 0  and c.delete_status = 0 " +
                " and b.meeting_id = c.id ";

        SqlKit s = new SqlKit();
        if(param!=null && !param.isEmpty()){
            if(querytype != null){
                s.buildSQL(querytype,param);
            }else {
                s.buildSQL(param);
            }
            sql+= s.getSql();
        }
        sql = sql+"order by a.id desc ";

        List<Record> list =  YmeetingController.getDB().find(sql,s.getParamArray());
        return list;
    }

}
